package com.tea.funct.controller;

import com.tea.common.annotation.Log;
import com.tea.common.core.controller.BaseController;
import com.tea.common.core.domain.AjaxResult;
import com.tea.common.core.page.TableDataInfo;
import com.tea.common.enums.BusinessType;
import com.tea.common.utils.poi.ExcelUtil;
import com.tea.funct.domain.TeaIncome;
import com.tea.funct.service.ITeaIncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收益记录Controller
 *
 * @author Sophia
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/funct/income")
public class TeaIncomeController extends BaseController {
    @Autowired
    private ITeaIncomeService teaIncomeService;

    /**
     * 查询收益记录列表
     */
    @PreAuthorize("@ss.hasPermi('funct:income:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaIncome teaIncome) {
        startPage();
        List<TeaIncome> list = teaIncomeService.selectTeaIncomeList(teaIncome);
        return getDataTable(list);
    }

    /**
     * 导出收益记录列表
     */
    @PreAuthorize("@ss.hasPermi('funct:income:export')")
    @Log(title = "收益记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaIncome teaIncome) {
        List<TeaIncome> list = teaIncomeService.selectTeaIncomeList(teaIncome);
        ExcelUtil<TeaIncome> util = new ExcelUtil<TeaIncome>(TeaIncome.class);
        util.exportExcel(response, list, "收益记录数据");
    }

    /**
     * 获取收益记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('funct:income:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(teaIncomeService.selectTeaIncomeById(id));
    }

    /**
     * 新增收益记录
     */
    @PreAuthorize("@ss.hasPermi('funct:income:add')")
    @Log(title = "收益记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaIncome teaIncome) {
        return toAjax(teaIncomeService.insertTeaIncome(teaIncome));
    }

    /**
     * 修改收益记录
     */
    @PreAuthorize("@ss.hasPermi('funct:income:edit')")
    @Log(title = "收益记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaIncome teaIncome) {
        return toAjax(teaIncomeService.updateTeaIncome(teaIncome));
    }

    /**
     * 删除收益记录
     */
    @PreAuthorize("@ss.hasPermi('funct:income:remove')")
    @Log(title = "收益记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(teaIncomeService.deleteTeaIncomeByIds(ids));
    }
}
